package tool;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MacroMaker {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length < 2){
			System.err.println("needs 2 args [inputPath] [outputPath]");
			return;
		}

		FileReader fr = null;
		BufferedReader br = null;

		String line = "";
		List<String> events = new ArrayList<String>();

		FileOutputStream fos =null;
		DataOutputStream dos = null;

		try {
			fr = new FileReader(args[0]);
			br = new BufferedReader(fr);

			while((line = br.readLine())!= null){
				events.add(line);
			}

			fos = new FileOutputStream(args[1]);
			dos = new DataOutputStream(fos);

			dos.writeByte(events.size());
			for(String e : events){
				String[] col = e.split("\t");
				dos.writeUTF(col[0]);
				dos.writeUTF(col[1]);
			}
			dos.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			try {
				br.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			try {
				fr.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				dos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
